﻿import QtQuick 2.0


import "../../js/util.js" as Util
/**
 * 临时弹出对话框，类似安卓的
 */
Item {
    id: rootToast
    Rectangle//BG
    {
        color: "#000"
        opacity: 0.1
        anchors.fill: parent
    }
    anchors.horizontalCenter: parent.horizontalCenter
    height: content.paintedHeight+m_lineValue*0.2
    visible: false

    onVisibleChanged: {
        if(content.paintedWidth>=m_root_id.width*0.8)
        {
            rootToast.width = m_root_id.width*0.8+m_lineValue*0.2
            content.wrapMode = Text.WrapAnywhere
        }
        else{
            rootToast.width = content.paintedWidth+m_lineValue*0.2
        }
    }

    AText {
        id: content
        anchors.centerIn: parent
        anchors.fill: parent
        color: "red"
        verticalAlignment: Text.AlignVCenter
        horizontalAlignment: Text.AlignHCenter
        wrapMode: Text.NoWrap
        font.pointSize: Util.isMobileDevice()? 14:12
    }

    Timer {
        id: closeTimerId
        interval: 3000
        repeat: false
        running: false
        onTriggered: {
            content.text = ""
            rootToast.visible = false;
        }
    }
    // 设置并显示提示消息
    function setMessage(text) {
        content.wrapMode = Text.NoWrap
        content.text = text
        rootToast.visible = true;
        closeTimerId.start()
    }
}
